﻿namespace Sharp.Platform.Mvc.Bootstrap
{
    /// <summary>
    /// 按钮扩展方法。
    /// </summary>
    public static class ButtonExtensions
    {
        public static ButtonBuilder Button(this BootstrapFactory factory)
        {
            return new ButtonBuilder();
        }
        public static ButtonBuilder Button(this BootstrapFactory factory, string title)
        {
            return factory.Button().Title(title);
        }
        public static ButtonBuilder Button(this BootstrapFactory factory, string title, string id)
        {
            return factory.Button().Title(title).Id(id);
        }
        /// <summary>
        /// 按钮类型
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ButtonBuilder Type(this ButtonBuilder factory, ButtonType type)
        {
            if (type == ButtonType.Reset)
            {
                return factory.Type().Reset();
            }
            else if (type == ButtonType.Submit)
            {
                return factory.Type().Submit();
            }
            else
            {
                return factory.Type().Button();
            }
        }
        /// <summary>
        /// 按钮样式
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ButtonBuilder Style(this ButtonBuilder factory, BootstrapStyle type)
        {
            if (type.HasFlag(BootstrapStyle.Default))
            {
                factory.Style().Default();
            }
            if (type.HasFlag(BootstrapStyle.Primary))
            {
                factory.Style().Primary();
            }
            if (type.HasFlag(BootstrapStyle.Success))
            {
                factory.Style().Success();
            }
            if (type.HasFlag(BootstrapStyle.Info))
            {
                factory.Style().Info();
            }
            if (type.HasFlag(BootstrapStyle.Warning))
            {
                factory.Style().Warning();
            }
            if (type.HasFlag(BootstrapStyle.Danger))
            {
                factory.Style().Danger();
            }
            if (type.HasFlag(BootstrapStyle.Block))
            {
                factory.Style().Block();
            }
            if (type.HasFlag(BootstrapStyle.Flat))
            {
                factory.Style().Flat();
            }


            return factory;
        }

        public static ButtonBuilder LoadingText(this ButtonBuilder factory, string text)
        {
            return factory.Attribute("data-loading-text", text, true);
        }
        public static ButtonBuilder Ico(this ButtonBuilder factory, IcoType text)
        {
            switch (text)
            {
                case IcoType.Back:
                    factory.Ico = "fa fa-backward";
                    break;
                case IcoType.Save:
                    factory.Ico = "fa fa-save";
                    break;
            }

          
            return factory;
        }
    }

    public enum ButtonType
    {
        Button, Submit, Reset
    }

    public enum IcoType
    {
        /// <summary>
        /// 保存
        /// </summary>
        Save,
        /// <summary>
        /// 返回
        /// </summary>
        Back
    }
}